import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  // vue router 没有帮我们维护一个新增后的路由规则，所以我们自己维护一个数组（静态加动态）
  routes: constantRoutes || []
}
const mutations = {
  setRoutes(state, otherRoutes) {
    // 每个人进来都应该是基于静态路由,新增一些动态路由,而不是累加push
    state.routes = [...constantRoutes, ...otherRoutes]
  }
}
//
const actions = {
  // 过滤出用户自己的路由规则， asyncRoutes menus
  fillterRoutes(context, menus) {
    console.log(asyncRoutes, menus, 171717)
    // item.children[0].name 判断的标准
    // item.children[0].name 如果在menus出现了 要保留
    const otherRoutes = asyncRoutes.filter(item => menus.includes(item.children[0].name))
    console.log(otherRoutes, 21212)
    context.commit('setRoutes', otherRoutes)
    return otherRoutes
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
